package com.feri.rbacsys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feri.rbacsys.dao.DepositoryDao;
import com.feri.rbacsys.dao.ImportOrderDao;
import com.feri.rbacsys.dto.ImportOrderDto;
import com.feri.rbacsys.entity.Depository;
import com.feri.rbacsys.entity.ImportOrder;
import com.feri.rbacsys.service.intf.ImportOrderService;
import com.feri.rbacsys.util.AuthUtil;
import com.feri.rbacsys.vo.R;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (ImportOrder)表服务实现类
 *
 * @author makejava
 * @since 2023-03-28 10:02:53
 */
@Service("importOrderService")
public class ImportOrderServiceImpl extends ServiceImpl<ImportOrderDao, ImportOrder> implements ImportOrderService {

    @Resource
    private ImportOrderDao dao;
    @Resource
    private DepositoryDao depositoryDao;

    @Override
    public R selectPage(Integer page, Integer size, String orderNum, String productName) {

        return R.ok(dao.all(new Page<>(page,size),orderNum,productName));
    }

    @Override
    public R importProduct(ImportOrder importOrder,Date deadLine) {
        importOrder.setUserId(AuthUtil.getUid());
        importOrder.setImportDate(new Date());
        dao.updateById(importOrder);
        Depository depository = new Depository();
        depository.setProductId(importOrder.getProductId());
        depository.setOrderNum(importOrder.getOrderNum());
        depository.setAmount(importOrder.getAmount());
        depository.setDeadline(deadLine);
        depository.setStatus(0);
        depository.setCtime(new Date());
        depositoryDao.insert(depository);
        return R.ok();
    }


}

